package com.itheima.d7_threadpool3;

import com.itheima.d7_threadpool2.MyCallable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 创建线程的第四种方式：executors工具类
 */

public class ExecutorsDemo3 {
    public static void main(String[] args) {
        //通过线程池工具类，Executors创建线程池对象
        ExecutorService pool = Executors.newFixedThreadPool(3);

        Future<String> f1 = pool.submit(new MyCallable(100));
        Future<String> f2 = pool.submit(new MyCallable(200));
        Future<String> f3 = pool.submit(new MyCallable(300));
        Future<String> f4 = pool.submit(new MyCallable(400));
        try {
            System.out.println(f1.get());
            System.out.println(f2.get());
            System.out.println(f3.get());
            System.out.println(f4.get());
        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }
}
